package final2107.night.day01;

public class SubStrCount {
    public static void main(String[] args) {
        String str ="hello ,world hello java hello c++hello";
        String subStr = "hello";
        int count = 0;
        int index=0; //从指定位置开始查找，同时表示查找到子串的下标

        while ((index=str.indexOf(subStr,index))!=-1){
            count++;
            index+=subStr.length();
        }
        System.out.println("出现的次数是："+count);
    }
}
